package com.jade.zsy.base.common;

import com.jade.framework.base.context.ApplicationContextUtils;
import com.jade.framework.cache.CacheService;

import javax.servlet.http.HttpServletRequest;

public class CacheServiceUtil
{

    public static void set(HttpServletRequest request, String key, Object value, int time)
    {
        if(!ConstantUtil.HAVE_MEMCACHE){
            request.getSession().setAttribute(key, value);
            return;
        }
        CacheService cacheService = ApplicationContextUtils.getBean("system_cacheService");
        cacheService.set(key,value, time);
    }

    public static Object get(HttpServletRequest request, String key)
    {
        if (!ConstantUtil.HAVE_MEMCACHE) {
            return request.getSession().getAttribute(key);
        }
        else {
            CacheService cacheService = ApplicationContextUtils.getBean("system_cacheService");
            return cacheService.get(key);
        }
    }
}
